using UnityEngine;
using System.Collections;

public class barredevieScript : MonoBehaviour {

    private GameObject ship;
    public float x0 = -288f;
    private float xOrigin;
    private float x;
    private float y;
    private float width;
    private float height;


	void Start () {
       x = guiTexture.pixelInset.x;
       y = guiTexture.pixelInset.y;
       xOrigin = x;
       width = guiTexture.pixelInset.width;
       height = guiTexture.pixelInset.height;
       guiTexture.pixelInset = new Rect ( x,y,width,height);
       ship = GameObject.Find("ship");
	}

   
	void FixedUpdate () {
        shipControllerScript shipScript = ship.GetComponent<shipControllerScript>();
        x = xOrigin - ((xOrigin - x0) * (shipScript.maxEnergy - shipScript.remainingEnergy) / shipScript.maxEnergy);
        guiTexture.pixelInset = new Rect(x, y, width, height);
	}
}
